﻿
@{
    ViewBag.Title = "因公出国表管理";
    Layout = "~/Views/Shared/_LayoutBase.cshtml";
}

@section styles{
    <link href="@Url.Content("~/Content/css/common/bootstrap-table/bootstrap-table.min.css")" rel="stylesheet" />
    <link href="@Url.Content("~/Content/css/common/animate/animate.min.css")" rel="stylesheet" />
}
<div id="dMain">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox" style="margin-bottom: 0px;">
            <div class="ibox-title">
                <h4>因公出国管理</h4>
            </div>
            <div class="ibox-content">
                <div id="toolbar">
                    @{
                        var pagePermissions = Html.GetPagePermissions(PermissionConst.ATTEND_OUT_MENU_ID);
                        if (pagePermissions.HasPermission(PermissionConst.ADD))
                        {
                            <a class="btn btn-sm btn-success radius" onclick="parent.createTab('3501','新建出国','@Url.Action("TripsEdit","Trips",new { area="Overseas"})')" style="margin-top: 10px;"><i class="iconfont icon-tianjia"></i>&nbsp; 新建出国</a>
                        }
                    }
                    <div class="text-danger" style="font-size: 14px; margin-top: 15px;margin-left: 10px;float:right; "><i class="iconfont icon-tuichiweixuan"></i>&nbsp;提示：双击行可查看该信息的详细！</div>
                </div>
                <table id="TripsDataTable"></table>
            </div>
        </div>
    </div>
</div>

@section scripts{
    <script src="@Url.Content("~/Content/js/common/bootstrap-table/bootstrap-table.min.js")"></script>
    <script src="@Url.Content("~/Content/js/common/bootstrap-table/locale/bootstrap-table-zh-CN.min.js")"></script>
    <script src="@Url.Content("~/Content/js/common/bootstrap-table/bootstrap-table-export.js")"></script>
    <script src="@Url.Content("~/Content/js/common/bootstrap-table/tableExport.js")"></script>
    <script src="@Url.Content("~/Content/js/common/bootstrap-table/bootstrap-table-cookie.js")"></script>
    <script src="@Url.Content("~/Content/js/common/from.js")"></script>
    <script src="@Url.Content("~/Content/js/common/Date.js")"></script>
    <script>
    //var tabHeight = 0;
        $(function () {
            $('#TripsDataTable').bootstrapTable({
                //  height: tabHeight + 50,
                url: '/Trips/GetTripsTableJsonResult',         //请求后台的URL（*）
                method: 'get',                      //请求方式（*）
                //data: $("#dJson").text() != "" ? JSON.parse($("#dJson").text()) : "",
                dataType: "json",
                columns: [
                    { checkbox: true },
                    {
                        title: "出国人", field: 'USER_ID', align: 'center'
                    },
                    {
                        title: "出国原因", field: 'TRIPS_TYPE', align: 'center'
                    },
                    {
                        title: "申请创建时间", field: 'CREATE_DATE', align: 'center', formatter: function (value, row, index) {
                            return new Date(value).Format("yyyy-MM-dd hh:mm:ss");
                        }
                    },
                    {
                        title: "申请提交时间", field: 'SUBMIT_TIME', align: 'center', formatter: function (value, row, index) {
                            return new Date(value).Format("yyyy-MM-dd hh:mm:ss");
                        }
                    },
                    {
                        title: "开始时间", field: 'TRIPS_TIME1', align: 'center', formatter: function (value, row, index) {
                            return new Date(value).Format("yyyy-MM-dd hh:mm:ss");
                        }
                    },
                    {
                        title: "结束时间", field: 'TRIPS_TIME2', align: 'center', formatter: function (value, row, index) {
                            return new Date(value).Format("yyyy-MM-dd hh:mm:ss");
                        }
                    },
                    {
                        title: "出国地点", field: 'DESTINATION', align: 'center'
                    },
                    {
                        title: "审批原因", field: 'REASON', align: 'center'
                    },
                    {
                        title: "审批人", field: 'LEADER_ID', align: 'center'
                    },
                    {
                        title: "审批状态", field: 'ALLOW', align: 'center', formatter: function (value, row, index) {
                            if (value == "1") {
                                return '<span  style="color: red;">已批准</span>';
                            }
                            else if (value == "2") { return '<span>未批准</span>'; }
                            else { return '<span>待审批</span>';}
                        }
                    },
                    {
                        field: '#',
                        title: "操作",
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value, row, index) {
                            var ids = row.ID;
                            var result = "";
                            result += '<a class="btn btn-info btn-xs btn-outline" onclick="Approval(' + ids + ')">审批</a>';
                    @if (pagePermissions.HasPermission(PermissionConst.EDIT))
                    {
                        <text>result += '<a class="btn btn-info btn-xs btn-outline" onclick="parent.createTab(\'3501\',\'编辑因公出国\',\'@Url.Action("TripsEdit", "Trips", new { area = "Overseas" })\/' + ids + '\')">编辑</a>'</text>
                    }

                    @if (pagePermissions.HasPermission(PermissionConst.DELETE))
                    {
                        <text>result += '<a class=" btn btn-danger btn-xs" onclick="del(' + ids + ')">删除</a>'</text>
                    }
                            return result;
                        }
                    }
                ],
                toolbar: '#toolbar',//工具按钮用哪个容器
                buttonsClass: "sm btn-white",//按钮class
                pageSize: 10,//分页条数
                clickToSelect: false,//设置true 将在点击行时，自动选择单选或复选框
                singleSelect: false,//为true则禁止多选
                cache: false,//是否缓存
                cookie: true,//是否启用cookie
                cookieIdTable: "Out",//cookie键值
                pagination: true,//是否分页
                showColumns: true,//是否显示所有的列
                showRefresh: true,//是否显示刷新按钮
                search: false,//是否启用搜索
                showPaginationSwitch: true,//是否显示分页切换按钮
                showExport: true,//是否启用导出
                striped: false,//是否显示行间隔色
                detailView: false,//是否显示切换视图列
                //detailFormatter: detailFormatter,//卡片视图内容格式化
                onDblClickRow: function (row, obj) { //双击行事件
                    // window.top.showFullPage("图像阅读器（" + (row.FileNo) + "）", "/See.aspx?FID=" + row.ID);
                    parent.createTab('3503', '因公出国明细', '@Url.Action("TripsDetails", "Trips", new { area = "Overseas" })/' + row.ID + '');
                },
                onClickRow: function (row, obj) { //单击行事件
                    $(obj).parent().find("tr").removeClass("selected");
                    $(obj).addClass("selected");

                    ////根据选中的行获取子表数据
                    //GetSonData(row.ID);
                },
                onSearch: function (text) {
                    if (text != "") {
                        $("#tabData tbody tr td:not(.bs-checkbox)").each(function (i) {
                            var str = "<span class=\"bg-yellow\">" + text + "</span>";
                            var NewText = $("#tabData tbody tr td:not(.bs-checkbox)").eq(i).text().replaceAll(text, str);
                            $("#tabData tbody tr td:not(.bs-checkbox)").eq(i).html(NewText);
                        })
                    }
                }
            });

        })

        function getName(arr, n, v) {
            for (var i = 0; i < arr.length; i++)
                if (arr[i][n] == v)
                    return arr[i]["Text"];
        }

        function del(id) {
            layer.confirm('是否删除此因公出国？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                var url = '@Url.Action("TripsDelete", "Trips", new { area = "Overseas" })\/' + id;
                $.get(url, function (result) {
                    $("#TripsDataTable").bootstrapTable('refresh', { url: '/Trips/GetTripsTableJsonResult' });
                    layer.msg('删除因公出国成功！', {
                        icon: 1,
                        time: 2000//2s后自动关闭
                    });
                });
            }, function () {

            });
        }

        function Approval(id){
            layer.confirm('是否通过此因公出国信息？', {
                btn: ['通过', '不通过'] //按钮
            }, function () {
                layer.open({
                    type: 1
                    , title: false //不显示标题栏
                    , closeBtn: false
                    , area: '300px;'
                    , shade: 0.8
                    , id: 'LAY_layuipro_T' //设定一个id，防止重复弹出
                    , btnAlign: 'c'
                    , moveType: 1 //拖拽模式，0或者1
                    , content: '<div style="line-height: 22px; font-weight: 300;"><textarea class="input normal form-control" cols="20" datatype="*" errormsg=" " id="REASON" name="REASON" nullmsg=" " rows="2" sucmsg=" "> </textarea><button style="margin-top: 5%; " type="button" class="btn btn-sm btn-success" onclick="TripsApproval(' + id + ',1)">提交</button></div>'
                });
            }, function () {
                layer.open({
                    type: 1
                    , title: false //不显示标题栏
                    , closeBtn: false
                    , area: '300px;'
                    , shade: 0.8
                    , id: 'LAY_layuipro_S' //设定一个id，防止重复弹出
                    , btnAlign: 'c'
                    , moveType: 1 //拖拽模式，0或者1
                    , content: '<div style=" line-height: 22px; font-weight: 300;"><textarea class="input normal form-control" cols="20" datatype="*" errormsg=" " id="REASON" name="REASON" nullmsg=" " rows="2" sucmsg=" "> </textarea><button style="margin-top: 5%; " type="button" class="btn btn-sm btn-success" onclick="TripsApproval(' + id + ',2)">提交</button></div>'
                });
            });
        }

        function TripsApproval(id,allow) {
            var strREASON = $("#REASON").val();
            var url = '@Html.Raw(Url.Action("TripsApproval", "Trips", new { area = "Overseas" }))?id=' + id + '&REASON=' + strREASON + '&ALLOW=' + allow;
            $.get(url, function (result) {
                $("#TripsDataTable").bootstrapTable('refresh', { url: '/Trips/GetTripsTableJsonResult' });
                layer.msg('审批成功！', {
                    icon: 1,
                    time: 2000//2s后自动关闭
                });
            });
            layer.closeAll();
        }
    </script>
}

